﻿using System;
using Light.Framework.Castle;
using Light.Framework.Contract;
using Light.Utility;

namespace Light.Framework.Model
{
    /// <summary>
    /// 超级用户（用于执行需要超级管理员权限做的任务）
    /// </summary>
    public class SuperUser : IDisposable
    {
        const string session_name = "session_light_framework_castle_superuser";

        public SuperUser()
        {
            if (ServerApplication.User != null && ServerApplication.User.Organization != null)
                WebHelper.SetSession(session_name, ServerApplication.User);

            ServerApplication.User = new Light.Framework.Model.User
            {
                Name = "超级用户",
                IsSuper = true,
                IsApprole = true,
            };
        }

        public void Dispose()
        {
            ServerApplication.User = WebHelper.GetSession<IUser>(session_name);
        }
    }
}
